package web.servlet.userlist.web.servelt;

import web.servlet.userlist.domin.PageBean;
import web.servlet.userlist.domin.User;
import web.servlet.userlist.service.UserService;
import web.servlet.userlist.service.UserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Author Administrator
 * @Date 2020/6/28 8:51
 **/
@WebServlet("/findUserByPageServlet")
public class FindUserByPageServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String cuttentPage = request.getParameter("cuttentPage");
        String rows = request.getParameter("rows");
        if(cuttentPage==null||cuttentPage.equals("")){
            cuttentPage="1";
        }
        if(rows==null||rows.equals("")){
            rows="5";
        }
        UserService service = new UserServiceImpl();
        PageBean<User> pb=service.findUserByPage(cuttentPage,rows);
        request.setAttribute("pb",pb);
        request.getRequestDispatcher("/userlist/list.jsp").forward(request,response);
    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    this.doPost(request,response);
    }
}
